<?php

/**
 * @author Rizky Tahara Shita
 * @website http://tahara.web.id
 * @email rizky.tahara@gmail.com
 * @copyright b'IT Cyber Solution
 */

class M_command_bar extends BZ_Model
{
/**
 * @section biskitZ Live Forms Model
 */

	/**
	 * @function view()
	 * @description generate the commands at the top of the view list
	 */
	public function view($prm_search_term = '', $prm_paging_data = '', $prm_search_use = TRUE, $prm_add_use = TRUE)
	{
		$return_value = '';
		/**
		 * @description init the command button
		 */
		$view_objects = array
			(
				'command_add_new' => ($prm_add_use && $this->access_rights['ADD'])
					? array
						(
							'function_name' => 'img'
							, 'function_attr' => array
								(
									array
									(
										'src' => site_url('themes/'.$this->web_data['BISKITZ']['SETTINGS']['BISKITZ_THEME_ADMIN'].'/images/icons/new.png')
										, 'class' => 'icon_command'
										, 'border' => 0, 'align' => 'left'
										, 'width' => 22, 'height' => 22
										, 'title' => $this->lang->line('tooltips_new')
										, 'alt' => $this->lang->line('button_new')
										, 'onclick' => 'javascript: js_common_link(\''.$this->tbl_attr['URL']['FORM'].'\');'
									)
									, TRUE
								)
						)
					: NULL

				, 'paging' => $prm_paging_data

				, 'search_box' => $prm_search_use
					? array
						(
							'function_name' => 'form_input'
							, 'function_attr' => array
								(
									array
									(
										'name' => 'txt_search', 'id' => 'txt_search'
										, 'size' => '20', 'maxlength' => '255'
									)
									, trim($prm_search_term) != '' ? $prm_search_term : $this->lang->line('tooltips_search')
								)
						)
					: NULL

				, 'search_command' => $prm_search_use
					? array
						(
							'function_name' => 'form_button'
							, 'function_attr' => array
								(
									array
									(
										'id' => 'btn_search'
										, 'title' => $this->lang->line('tooltips_search')
									)
									, $this->lang->line('button_search')
									, 'onclick="javascript: form.submit();"'
								)
						)
					: NULL
			);
		foreach ($view_objects as $val)
		{
			if ( ! is_null($val))
			{
				if (is_array($val))
				{
					$return_value .= call_user_func_array($val['function_name'], $val['function_attr']);
				}
				else
				{
					$return_value .= $val;
				}
			}
		}


		return $return_value;
	}


	/**
	 * @function form()
	 * @description generate the commands at the top of the form
	 */
	public function form($prm_use = 'TRUE', $prm_command_new = TRUE, $prm_command_save = TRUE, $prm_command_add_detail = FALSE, $prm_command_back = TRUE, $prm_command_view = TRUE)
	{
		$return_value = array
			(
				'USE' => $prm_use
				, 'NEW' => $prm_command_new
						? $this->access_rights['ADD']
							? array
								(
									'TITLE' => $this->lang->line('tooltips_new')
									, 'URL' => $this->tbl_attr['URL']['FORM']
									, 'CLEDITOR_COUNT' => is_array($prm_command_new) ? $prm_command_new['CLEDITOR_COUNT'] : NULL
								)
							: NULL
						: NULL
				, 'ADD_DETAIL' => $prm_command_add_detail
						? $this->access_rights['ADD']
							? array
								(
									'TITLE' => $this->lang->line('tooltips_add_detail')
									, 'ONCLICK' => is_array($prm_command_add_detail) ? $prm_command_add_detail['ONCLICK'] : "$('#btn_add_detail').click();"
								)
							: NULL
						: NULL
				, 'SAVE' => $prm_command_save
						? array
							(
								'TITLE' => (is_array($prm_command_save) && isset($prm_command_save['TITLE'])) ? $prm_command_save['TITLE'] : $this->lang->line('tooltips_save')
								, 'ONCLICK' => (is_array($prm_command_save) && isset($prm_command_save['ONCLICK'])) ? $prm_command_save['ONCLICK'] : "$('#btn_save').click();"
							)
						: NULL


				, 'BACK' => $prm_command_back
						? array
							(
								'TITLE' => $this->lang->line('tooltips_back')
							)
						: NULL
				, 'VIEW' => $prm_command_view
						? array
							(
								'TITLE' => $this->lang->line('tooltips_view_data')
								, 'URL' => $this->tbl_attr['URL']['VIEW']
							)
						: NULL
			);


			return $return_value;
	}




}

/** End of file M_command_bar.php */
/** Location: ./biskitz_mpc/biskitz/models/admin/m_command_bar.php */
